package com.xiantm.study.thread.threadpermessage;

public class MagicMethod2 {
    public static void main(String[] args) {
        System.out.println("Main Start");
        enter(new Object());
        System.out.println("Main End");
    }

    public static void enter(Object obj){
        System.out.println("Step 1.");
        magic(obj);
        System.out.println("Step 2.");
        synchronized (obj) {
            System.out.println("Step 3.");
        }
    }
    public static void magic(final Object obj){
        final Object o = new Object();
        new Thread(() -> {
            synchronized (obj){
                synchronized (o){
                    o.notify();
                }
                for(;;);
            }
        }).start();
        synchronized (o){
            try {
                o.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
